/*
 * File:   relationtest.c
 * Author: ossi
 *
 * Created on 06-Nov-2011, 17:58:42
 */

#include <stdio.h>
#include <stdlib.h>
#include <CUnit/Basic.h>
#include "relation.h"
#include "person.h"

/*
 * CUnit Test Suite
 */

int init_suite(void) {
    return 0;
}

int clean_suite(void) {
    return 0;
}

void testInt_to_relt() {
    rel_t result = int_to_relt(0);
    CU_ASSERT(result == REL_CHILD);
    result = int_to_relt(1);
    CU_ASSERT(result == REL_MARRIAGE);
    result = int_to_relt(2);
    CU_ASSERT(result == REL_OTHER);
    result = int_to_relt(3);
    CU_ASSERT(result == REL_INVALID_VALUE);
    result = int_to_relt(-1);
    CU_ASSERT(result == REL_INVALID_VALUE);
    result = int_to_relt(8);
    CU_ASSERT(result == REL_INVALID_VALUE);
    
}

void testRel_equals() {
    person p1,p2;
    p1.name = L"a";
    p2.name = L"b";
    
    relation* relation1 = rel_new(&p1,&p2,REL_OTHER);
    relation* relation2=rel_new(&p1,&p2,REL_OTHER);
    relation* relation3=rel_new(&p1,&p2,REL_CHILD);
    
    CU_ASSERT(rel_equals(relation1, relation2));
    CU_ASSERT(!rel_equals(relation1, relation3));
    CU_ASSERT(!rel_equals(relation2, relation3));
    
}

void testRelt_to_int() {
    CU_ASSERT(relt_to_int(REL_CHILD) == 0);
    CU_ASSERT(relt_to_int(REL_MARRIAGE) == 1);
    CU_ASSERT(relt_to_int(REL_OTHER) == 2);
    CU_ASSERT(relt_to_int(REL_INVALID_VALUE) == -1);
}

int main() {
    CU_pSuite pSuite = NULL;

    /* Initialize the CUnit test registry */
    if (CUE_SUCCESS != CU_initialize_registry())
        return CU_get_error();

    /* Add a suite to the registry */
    pSuite = CU_add_suite("relationtest", init_suite, clean_suite);
    if (NULL == pSuite) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Add the tests to the suite */
    if ((NULL == CU_add_test(pSuite, "testInt_to_relt", testInt_to_relt)) ||
            (NULL == CU_add_test(pSuite, "testRel_equals", testRel_equals)) ||
            (NULL == CU_add_test(pSuite, "testRelt_to_int", testRelt_to_int))) {
        CU_cleanup_registry();
        return CU_get_error();
    }

    /* Run all tests using the CUnit Basic interface */
    printf("relationtest.c:");
    CU_basic_set_mode(CU_BRM_VERBOSE);
    CU_basic_run_tests();
    CU_cleanup_registry();
    return CU_get_error();
}
